from pyamf.remoting.gateway.wsgi import WSGIGateway
from wsgiref import simple_server

import rpyc

from dexen.system.client import client

class FlexService:
    def echo(self, data):
        print "I am in Echo"
        return data
    def connect_to_server(self, url):
        print "The url is", url
        client.connect_to_server(url)
    
    def start_script(self, schema, step, file, function, project, id):
        client.start_script(schema, step, file, function, project, id)
    
    def upload_zip_file(self, file):
        # file is string referring to the full path of the zip file
        client.upload_zip_file(file)
    
    def get_all_schemas(self):
        schema_list = client.get_all_schemas()
        ret = []
        for schema in schema_list:
            print "The name", schema[0]
            ret.append(schema[0])
        return ret
    

services = {
    'pyamfService':FlexService,
}

if __name__ == "__main__":
    
    gw = WSGIGateway(services)
    
    httpd = simple_server.WSGIServer(
        ("localhost", 8000),
        simple_server.WSGIRequestHandler,
    )
    
    httpd.set_app(gw)
    print "Running Hello World AMF gateway on http://localhost:8000"
    
    
    client = Backend()
    #connect_to_server("localhost")
    #upload_zip_file("C:\eclipse-workspace\medden\src\medden\schemas\input.zip")
    #upload_zip_file("C:\eclipse-workspace\medden\src\medden\schemas\input5.zip")
    #get_all_schemas()
    
    httpd.serve_forever()    
    
    